package com.example.demo.Controller;

import com.example.demo.model.UserInfo;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@RequestMapping("/respose")
@Controller
public class RequestController {
    @RequestMapping("/returnHtmlPage")
    public String returnHtmlPage(){
        return "/hello.html";
    }

    @ResponseBody
    @RequestMapping("/returnHtmlData")
    public String returnHtmlData(){
        return "我是蔡徐坤!!!";
    }

    @ResponseBody
    @RequestMapping("/returnHtml")
    public String returnHtml(){
        return "<h1>html<h1>";
    }

    @ResponseBody
    @RequestMapping("/returnJson")
    public UserInfo returnJson(){
        UserInfo user = new UserInfo();
        user.setName("cxk!!");
        user.setAge(25);
        return user;
    }

    @ResponseBody
    @RequestMapping("/setStatus")
    public UserInfo setStatus(HttpServletResponse response){

        UserInfo user = new UserInfo();
        user.setName("cxk!!");
        user.setAge(25);
        response.setStatus(500);
        return user;


    }




    @ResponseBody
    @RequestMapping(value = "/setHeader",produces = "application/json")
    public String setHeader(){

        return "{\"success\":true}";
    }

    @ResponseBody
    @RequestMapping( "/setHeader2")
    public String setHeader2(HttpServletResponse response){

        response.setHeader("muKey","myValue");
        return "success";


    }




}


